if(typeof Object.create!=='function'){ Object.create=function (obj){ function F(){}; F.prototype=obj; return new F(); };} (function ($, window, document, undefined){ var Instagram={ init: function (options, elem){ var self=this; self.elem=elem; self.$elem=jQuery(elem); self.api='https://api.instagram.com/v1', self.accessData=jQuery.fn.spectragram.accessData, self.options=jQuery.extend({}, jQuery.fn.spectragram.options, options); }, getRecentMedia: function (count){ var self=this, getData='/users/self/media/recent/?access_token='+ self.accessData.accessToken +'&count='+ count; self.fetch(getData).done(function(results){ self.display(results); }); }, getUserFeed: function (){ var self=this; self.getRecentMedia(self.options.max); }, getPopular: function (){ var self=this, getData='/media/popular?client_id=' + self.accessData.clientID + '&access_token='+ self.accessData.accessToken + ''; self.fetch(getData).done(function(results){ self.display(results); }); }, getRecentTagged: function (){ var self=this, getData='/tags/' + self.options.query + '/media/recent?client_id=' + self.accessData.clientID + '&access_token='+ self.accessData.accessToken + ''; self.fetch(getData).done(function(results){ if(results.data.length){ self.display(results); }else{ jQuery.error('Spectagram.js - Error: the tag ' + self.options.query + ' does not have results.'); };}); }, fetch: function (getData){ var self=this, getUrl=self.api + getData; return jQuery.ajax({ type: "GET", dataType: "jsonp", cache: false, url: getUrl }); }, display: function (results){ var self=this, setSize=self.options.size, size, max=(self.options.max >=results.data.length) ? results.data.length:self.options.max; if(results.data.length===0){ self.$elem.append(jQuery(self.options.wrapEachWith).append(self.options.notFoundMsg)); }else{ for (var i=0; i < max; i++){ if(setSize=="small"){ size=results.data[i].images.thumbnail.url; } else if(setSize=="medium"){ size=results.data[i].images.low_resolution.url; }else{ size=results.data[i].images.standard_resolution.url; } var titleIMG; if(results.data[i].caption!=null){ titleIMG='title="' + jQuery('').text(results.data[i].caption.text).html() +'"'; } self.$elem.append(jQuery(self.options.wrapEachWith).append("")); }} if(typeof self.options.complete==='function'){ self.options.complete.call(self); }} }; jQuery.fn.spectragram=function(method, options){ if(jQuery.fn.spectragram.accessData.clientID){ this.each(function (){ var instagram=Object.create(Instagram); instagram.init(options, this); if(instagram[method]){ return instagram[method](this); }else{ jQuery.error('Method ' + method + ' does not exist on jQuery.spectragram'); }}); }else{ jQuery.error('You must define an accessToken and a clientID on jQuery.spectragram'); }}; jQuery.fn.spectragram.options={ max: 10, query: 'coffee', size: 'medium', wrapEachWith: '
  • ', complete:null }; jQuery.fn.spectragram.accessData={ accessToken: null, clientID: null };})(jQuery, window, document);